
<div class="form">
	<p></p>
	<form id="ndk-health-form" method="post" action="<?php echo Yii::app()->createUrl('/finance/showStatistic/t/2'); ?>" target="_blank">
		<div class="row">
			<div class="col-md-4">
				<div class="widget box">
					<div class="widget-header">
						<h4><i class="icon-reorder"></i> Report Statistic </h4>
					</div>
					<div class="widget-content">
						
						<div class="control-group">
						<label class="control-label">Bulan</label>
						<div class="controls">
							<select id="bulan" name="bulan" class="form-control">
						<option value="01">Januari</option>
						<option value="02">Februari</option>
						<option value="03">Maret</option>
						<option value="04">April</option>
						<option value="05">Mei</option>
						<option value="06">Juni</option>
						<option value="07">Juli</option>
						<option value="08">Agustus</option>
						<option value="09">September</option>
						<option value="10">Oktober</option>
						<option value="11">November</option>
						<option value="12">Desember</option>
						</select>
						</div>
						</div>
						
						<div class="control-group">
						<label class="control-label">Tahun</label>
						<div class="controls">
							<input type="text" name="thn" id="thn" class="form-control" />
						</div>
						</div>
						
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-md-4">
				<div class="form-actions">
					<button class="btn btn-primary btn-large" id="btn_prev" type="button">Preview</button>
					<button class="btn btn-primary btn-large" name="yt0" type="submit">Cetak</button>
				</div>
			</div>
		</div>
	</form>
</div>


<div class="form">
Rupiah
<br/>
<table class="table table-hover table-striped table-bordered table-highlight-head" id="tbl_statistic">
	<thead>
		<tr>
			<th style="text-align:center" rowspan="2">Client Name</th>
			<th style="text-align:center" rowspan="2">Type Of Insurance</th>
			<th style="text-align:center" rowspan="2">Currency</th>
			<th style="text-align:center" colspan="2">Current Period</th>
			<th style="text-align:center" colspan="2">Last Year Same Period</th>
		</tr>
		<tr>
			<th style="text-align:center">Gross Premium</th>
			<th style="text-align:center">Brokerage</th>
			<th style="text-align:center">Gross Premium</th>
			<th style="text-align:center">Brokerage</th>
		</tr>
	</thead>
	<tbody id="body_rupiah">
	
	</tbody>
</table>
	
</div>

<div class="form">
Dolar
<br/>
<table class="table table-hover table-striped table-bordered table-highlight-head" id="tbl_statistic_dolar">
	<thead>
		<tr>
			<th style="text-align:center" rowspan="2">Client Name</th>
			<th style="text-align:center" rowspan="2">Type Of Insurance</th>
			<th style="text-align:center" rowspan="2">Currency</th>
			<th style="text-align:center" colspan="2">Current Period</th>
			<th style="text-align:center" colspan="2">Last Year Same Period</th>
		</tr>
		<tr>
			<th style="text-align:center">Gross Premium</th>
			<th style="text-align:center">Brokerage</th>
			<th style="text-align:center">Gross Premium</th>
			<th style="text-align:center">Brokerage</th>
		</tr>
	</thead>
	<tbody id="body_dolar">
	
	</tbody>
</table>
	
</div>

<div class="form">
Euro
<br/>
<table class="table table-hover table-striped table-bordered table-highlight-head" id="tbl_statistic_euro">
	<thead>
		<tr>
			<th style="text-align:center" rowspan="2">Client Name</th>
			<th style="text-align:center" rowspan="2">Type Of Insurance</th>
			<th style="text-align:center" rowspan="2">Currency</th>
			<th style="text-align:center" colspan="2">Current Period</th>
			<th style="text-align:center" colspan="2">Last Year Same Period</th>
		</tr>
		<tr>
			<th style="text-align:center">Gross Premium</th>
			<th style="text-align:center">Brokerage</th>
			<th style="text-align:center">Gross Premium</th>
			<th style="text-align:center">Brokerage</th>
		</tr>
	</thead>
	<tbody id="body_euro">
	
	</tbody>
</table>
	
</div>

<script type="text/javascript">
function formatCurrency(total) {
    var neg = false;
    if(total < 0) {
        neg = true;
        total = Math.abs(total);
    }
    return (neg ? "" : '') + parseFloat(total, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
}

$("#btn_prev").click(function(e){
	var isi_cicilan = "";
	$.ajax({
			type:"POST",
            url:"<?php echo Yii::app()->createUrl('/finance/showStatistic/t/1'); ?>",
			data:{},
			dataType:"json",
            success:function(data){
				$("#body_rupiah").html("");
				$("#body_dolar").html("");
				$("#body_euro").html("");
				var total_debet_rp = parseInt(0);
				var total_kredit_rp = parseInt(0);
				
				var total_debet_dolar = parseInt(0);
				var total_kredit_dolar = parseInt(0);
				
				var total_debet_euro = parseInt(0);
				var total_kredit_euro = parseInt(0);
				
				for(var i=0;i<data.length;i++){
					if(data[i].jns_mata_uang == 'Rupiah'){
						$("#body_rupiah").append("<tr>" +
						"<td>"+data[i].name+"</td>"+
						"<td>"+data[i].jns_insurance+"</td>"+
						"<td>"+data[i].jns_mata_uang+"</td>"+
						"<td>"+formatCurrency(data[i].gross_premi)+"</td>"+
						"<td>"+formatCurrency(data[i].brokerage)+"</td>"+
						"<td>0</td>"+
						"<td>0</td>"+
						"</tr>");
						total_debet_rp += parseInt(data[i].debet);
						total_kredit_rp += parseInt(data[i].kredit);
					}else if(data[i].jns_mata_uang == 'Dollar'){
						$("#body_dolar").append("<tr>" +
						"<td>"+data[i].name+"</td>"+
						"<td>"+data[i].jns_insurance+"</td>"+
						"<td>"+data[i].jns_mata_uang+"</td>"+
						"<td>"+formatCurrency(data[i].gross_premi)+"</td>"+
						"<td>"+formatCurrency(data[i].brokerage)+"</td>"+
						"<td>0</td>"+
						"<td>0</td>"+
						"</tr>");
						total_debet_dolar += parseInt(data[i].debet);
						total_kredit_dolar += parseInt(data[i].kredit);
					}else if(data[i].jns_mata_uang == 'Euro'){
						$("#body_euro").append("<tr>" +
						"<td>"+data[i].name+"</td>"+
						"<td>"+data[i].jns_insurance+"</td>"+
						"<td>"+data[i].jns_mata_uang+"</td>"+
						"<td>"+formatCurrency(data[i].gross_premi)+"</td>"+
						"<td>"+formatCurrency(data[i].brokerage)+"</td>"+
						"<td>0</td>"+
						"<td>0</td>"+
						"</tr>");
						total_debet_euro += parseInt(data[i].debet);
						total_kredit_euro += parseInt(data[i].kredit);
					}
				}
				//row total
				/*$("#body_rupiah").append("<tr>" +
						"<td colspan='3' align='right'>Total</td>"+
						"<td>"+formatCurrency(total_debet_rp)+"</td>"+
						"<td>"+formatCurrency(total_kredit_rp)+"</td>"+
						"</tr>");
						
				$("#body_dolar").append("<tr>" +
						"<td colspan='4' align='right'>Total</td>"+
						"<td>"+total_debet_dolar+"</td>"+
						"<td>"+total_kredit_dolar+"</td>"+
						"</tr>");
						
				$("#body_euro").append("<tr>" +
						"<td colspan='4' align='right'>Total</td>"+
						"<td>"+total_debet_euro+"</td>"+
						"<td>"+total_kredit_euro+"</td>"+
						"</tr>");
						
				//row grand total
				$("#body_rupiah").append("<tr>" +
						"<td colspan='3' align='right'>Grand Total</td>"+
						"<td colspan='2'>"+formatCurrency((parseInt(total_debet_rp) - parseInt(total_kredit_rp)))+"</td>"+
						"</tr>");
						
				$("#body_dolar").append("<tr>" +
						"<td colspan='4' align='right'>Total</td>"+
						"<td colspan='2'>"+(parseInt(total_debet_dolar) - parseInt(total_kredit_dolar))+"</td>"+
						"</tr>");
						
				$("#body_euro").append("<tr>" +
						"<td colspan='4' align='right'>Total</td>"+
						"<td colspan='2'>"+(parseInt(total_debet_euro) - parseInt(total_kredit_euro))+"</td>"+
						"</tr>");
				*/
				
			}
	});
});//end click
</script>